package Dao;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import Entity.Machine;
import mapper.Coursemapper;
import mapper.Machinemapper;


public class machinedao implements Machinemapper{
	private  static Machinemapper machinemapper;
	private  static SqlSession session;

	public machinedao() throws IOException {
	 	String resource ="mybatis-config.xml";
		InputStream inputstream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlsessionfactory = new SqlSessionFactoryBuilder().build(inputstream);
		 session = sqlsessionfactory.openSession();
        machinemapper = session.getMapper(Machinemapper.class);
    }
	public void close(){
		this.session.close();
	}
	@Override
	public boolean CreatMachine(Machine machine) {
		
		Boolean iuser = this.machinemapper.CreatMachine(machine);
		if(iuser == true){
			session.commit();
		}else{
			session.rollback();
		}

		return iuser;
	}

	@Override
	public List<Machine> getAllMachine() {
		
		List<Machine> selectList = this.machinemapper.getAllMachine();

		return selectList;
	}

	@Override
	public List<Machine> getAllMachineByrId(String rid) {
	
		List<Machine> selectList = this.machinemapper.getAllMachineByrId(rid);

		return selectList;
	}

	@Override
	public Machine getAllMachineById(String rid, String mid) {
		
		Machine selectList = this.machinemapper.getAllMachineById(rid,mid);
	
		return selectList;
	}

	@Override
	public void setdamage(String rid, String mid) {
		
		this.machinemapper.setdamage(rid,mid);

		session.commit();
		
		
	}
	@Override
	public void getdamage(String rid, String mid) {
		this.machinemapper.getdamage(rid,mid);

		session.commit();
		
	}

}
